/*
 * util.h
 *
 *  Created on: 13-Sep-2014
 *      Author: ali
 */

#ifndef UTIL_H_
#define UTIL_H_
#include <math.h>
#include <iostream>
#include "Constant.h"
using namespace std;
const double disD0 = sqrt(Efs / Emp);
const double disD1 = sqrt(Efs1 / Emp1);

static double TxPowerCalc(double dist, int msglen)
{
	double EnergyUse = 0.00;
	if (dist <= disD0)
	{
		EnergyUse = (msglen * (Eelec + EDA)) + (msglen * Efs * pow(dist, 2));
	}
	else
	{
		EnergyUse = (msglen * (Eelec + EDA)) + (msglen * Emp * pow(dist, 4));
	}
	return EnergyUse;
}
static double TxPowerCalcCHtoCH(double dist, int msglen)
{
	double EnergyUse = 0.00;
	if (dist > disD1)
	{
		EnergyUse = (msglen * ETX) + (msglen * Emp1 * pow(dist, 4));
	}
	else
	{
		EnergyUse = (msglen * ETX) + (msglen * Efs1 * pow(dist, 2));
	}
	return EnergyUse;
}

static double RxPowerCalc(int msglen)
{
	return (msglen * Eelec);
}

const double dPowerForLEACHAD = TxPowerCalc(LEACH_AD_DISTANCE, LEACH_AD_MESSAG);

#endif /* UTIL_H_ */
